package name;

import java.io.DataOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class ChstClient {
    public static void main(String[] args) throws Exception {
        //1.创建一Socket对象，并同时请求与服务端相连接
        Socket socket = new Socket("127.0.0.2", 1315);
        //2.从Socket管道当中得到一个字节输出流，用来发数据给服务器程序
        OutputStream outputStream = socket.getOutputStream();
        //将其包装成一个数据输入流
        DataOutputStream dps = new DataOutputStream(outputStream);
        new ChstClientReadThread(socket).start();
        Scanner sc= new Scanner(System.in);
        //使用writeUTF（）给服务端发送消息
        while (true) {
            System.out.println("请输入您给别人发送的消息");
            String magges=sc.next();
            dps.writeUTF(magges);
            if (magges.equals("exit")) {
                System.out.println("欢迎下次聊天");
                socket.close();
                dps.close();
                break;

            }
        }
    }

}
